package com.jckl.foodathon.fragments;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.jckl.foodathon.R;
import com.jckl.foodathon.activities.HomeActivity;
import com.jckl.foodathon.model.BlogsListWidget;
import com.jckl.foodathon.model.Store;
import com.jckl.foodathon.services.store.GetBlogs;
import com.jckl.foodathon.widget.BlogsListAdapter;

public class BlogListFragment extends Fragment implements OnItemClickListener{
	
	ListView blog_result_list;
	String storeName;
	List<BlogsListWidget> displayBlogs;

	public BlogListFragment() {
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_blog_result, container, false);
		
		blog_result_list	= (ListView) rootView.findViewById(R.id.blog_result_list);
		storeName 			= ((HomeActivity)getActivity()).getStoreName();
		
		blog_result_list.setOnItemClickListener(this);
		
		List<BlogsListWidget> blogResultWidget = new ArrayList<BlogsListWidget>();
		BlogsListAdapter adapter = new BlogsListAdapter(getActivity().getApplicationContext(), blogResultWidget);

		Store store = new Store();
		store.setName(storeName);
		
		GetBlogs getBlogs = new GetBlogs();
		getBlogs.GetBlogsByStore(getActivity(), rootView, store, blogResultWidget, adapter);
		
		displayBlogs = blogResultWidget;
		
		
		return rootView;
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
//		StoresListWidget store = displayStores.get(arg2);
//		((HomeActivity)getActivity()).setStoreName(store.getStoreName());
//		
//		Toast.makeText(getActivity().getApplicationContext(), "You clicked on :"+store.getStoreName(), Toast.LENGTH_LONG).show();
	}

}